import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {
  HomeRouteConfig,
  LoginRouteConfig,
  AppLaunchConfig,
} from './RouteConfig';
import {
  HomeStackNavigationConfig,
  LoginStackNavigationConfig,
} from './NavigatorConfig';

/**
 * 导航结构不同模块功能分开放入不同的导航栈内，全部放入一个导航栈，容易内存泄露
 */

const AppLaunchNavigation = createStackNavigator(AppLaunchConfig);
const LoginNavigation = createStackNavigator(
  LoginRouteConfig,
  LoginStackNavigationConfig,
);

// 主页导航栈
const HomeNavigation = createStackNavigator(
  HomeRouteConfig,
  HomeStackNavigationConfig,
);

const SwicthNavigation = createSwitchNavigator(
  {
    Launch: AppLaunchNavigation,
    Home: HomeNavigation,
    Login: LoginNavigation,
  },
  {
    initialRouteName: 'Launch',
    backBehavior: 'none',
  },
);

/**
 * 导航配置的优先级是： 页面的静态配置 > routeConfigMap > stackConfig
 * */
export default createAppContainer(SwicthNavigation);
